﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using RainyPWS.Common;

namespace RainyPWS.Model
{
    public class MRecord : Model
    {
        public enum ColumnList
        {
            ID,
	        Title,
	        TypeID,
            Status,
	        Author,
	        AddedDate,
	        Summary,
	        KeyWorks,
            Content
        }

        private const int MAX_COLUMN_INDEX = 9;

        public MRecord() : this(true) { }

        public MRecord(bool initDBNull) : base(MAX_COLUMN_INDEX, initDBNull) { }

        public MRecord(IDataReader rdr)
        {
            moData = new object[MAX_COLUMN_INDEX];
            rdr.GetValues(moData);
        }

        public int ID
        {
            get
            {
                object o = base.GetValue<ColumnList>(ColumnList.ID);
                if (o == DBNull.Value) return 0;
                return Convert.ToInt32(o);
            }
            set { base.SetValue<ColumnList>(ColumnList.ID, value); }
        }
        public string Title
        {
            get
            {
                object o = base.GetValue<ColumnList>(ColumnList.Title);
                if (o == DBNull.Value) return string.Empty;
                return o.ToString();
            }
            set { base.SetValue<ColumnList>(ColumnList.Title, value); }
        }
        public int TypeID
        {
            get
            {
                object o = base.GetValue<ColumnList>(ColumnList.TypeID);
                if (o == DBNull.Value) return 0;
                return Convert.ToInt32(o);
            }
            set { base.SetValue<ColumnList>(ColumnList.TypeID, value); }
        }
        public int Status
        {
            get
            {
                object o = base.GetValue<ColumnList>(ColumnList.Status);
                if (o == DBNull.Value) return RecordStatus.Ready;
                return Convert.ToInt32(o);
            }
            set { base.SetValue<ColumnList>(ColumnList.Status, value); }
        }
        public string Author
        {
            get
            {
                object o = base.GetValue<ColumnList>(ColumnList.Author);
                if (o == DBNull.Value) return string.Empty;
                return o.ToString();
            }
            set { base.SetValue<ColumnList>(ColumnList.Author, value); }
        }
        public DateTime AddedDate
        {
            get
            {
                object o = base.GetValue<ColumnList>(ColumnList.AddedDate);
                if (o == DBNull.Value) return DateTime.MinValue;
                return Convert.ToDateTime(o);
            }
            set { base.SetValue<ColumnList>(ColumnList.AddedDate, value); }
        }
        public string Summary
        {
            get
            {
                object o = base.GetValue<ColumnList>(ColumnList.Summary);
                if (o == DBNull.Value) return string.Empty;
                return o.ToString();
            }
            set { base.SetValue<ColumnList>(ColumnList.Summary, value); }
        }
        public string KeyWorks
        {
            get
            {
                object o = base.GetValue<ColumnList>(ColumnList.KeyWorks);
                if (o == DBNull.Value) return string.Empty;
                return o.ToString();
            }
            set { base.SetValue<ColumnList>(ColumnList.KeyWorks, value); }
        }
        public string Content
        {
            get
            {
                object o = base.GetValue<ColumnList>(ColumnList.Content);
                if (o == DBNull.Value) return string.Empty;
                return o.ToString();
            }
            set { base.SetValue<ColumnList>(ColumnList.Content, value); }
        }
    }
}
